#include "common.h"
#include "xobjlist.h"
//-----------------------------------------------------------------------------
XObjList::XObjList(XGame* game)
{
     pGame = game;
}
//-----------------------------------------------------------------------------
void XObjList::addObject(XObject* pObject)
{
    objects.push_front(pObject);
}
//-----------------------------------------------------------------------------
void XObjList::drawObjects()
{
    XObject* pObject;
    if(!objects.empty())
    {
        for(OBJECTLIST_ITERATOR iterator=objects.begin(); iterator != objects.end(); iterator++)
        {
            pObject=*iterator;
            pObject->draw();
        }
    }
}
//-----------------------------------------------------------------------------
void XObjList::processObjects()
{
    if(!objects.empty())
    { 
        OBJECTLIST_ITERATOR iterator = objects.begin();
        XObject* pObject;

        while(iterator != objects.end())
        {
            pObject=*iterator;

            if(!pObject->process())
            {
                delete pObject;
                iterator = objects.erase(iterator);
            }
            else
            iterator++;
        }

        iterator = objects.begin();

        while(iterator != objects.end())
        {
            pObject=*iterator;

            OBJECTLIST_ITERATOR iterator2 = objects.begin();
            XObject* pObject2;

            while(iterator2 != objects.end())
            {
                pObject2=*iterator2;

                if(pObject != NULL && pObject2 != NULL && pObject != pObject2)
                pObject->collisionTest(pObject2);

                iterator2++;
            }

            iterator++;
        }
    }
}
//-----------------------------------------------------------------------------
XObjList::~XObjList()
{
    XObject* pObject;
    if(!objects.empty())
    {
        for(OBJECTLIST_ITERATOR iterator=objects.begin(); iterator != objects.end(); iterator++)
        {
            pObject=*iterator;
            DEL(pObject);
        }
    }
    objects.clear();
}
//-----------------------------------------------------------------------------
